package com.property.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.property.biz.ComplaintBiz;
import com.property.biz.DisposeBiz;
import com.property.entity.Complaint;
import com.property.entity.ComplaintDispose;
import com.property.entity.Management;
import com.property.entity.User;

@Controller
@RequestMapping("/main")
public class ComplaintController {
	
	
	@Autowired
	private ComplaintBiz complaintBiz;
	
	
	@RequestMapping("/complaint")
	public String compla(Model model,Integer index,HttpSession session){
		index=index==null?1:index;
		int size=5;
		Management management=(Management) session.getAttribute("management");
		int indexs=(index-1)*size;
		String type="报修";
		int sums = complaintBiz.comCount(type, management.getCommunity().getId());
		int sum = (int) Math.ceil((double)sums/size);
		List<Complaint> list=complaintBiz.getAll(indexs, size, type, management.getCommunity().getId());
		model.addAttribute("compla", list);
		model.addAttribute("index", index);
		model.addAttribute("sum", sum);
		return "main/complaint";
	}
	
	@RequestMapping("/detail")
	public String detail(Model model,Integer id){
		id=id==null?1:id;
		Complaint complaint = complaintBiz.ComAll(id);
		complaintBiz.updateCom(id);
		model.addAttribute("detail", complaint);
		return "main/detail";
	}
	
}
